﻿using Repid.Entity.Basic;
using Repid.MvcExtension.Controllers;
using Repid.Core.Aop;
using Repid.Utility.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Repid.MvcApplication.Areas.Manage.Controllers
{
    public class FunctionController : ManageController
    {
        public ActionResult List()
        {
            return View();
        }

        public ActionResult Page(string id)
        {
            BasicFunction model;

            if (string.IsNullOrEmpty(id))
            {
                model = new BasicFunction();

                model.Type = "func";
            }
            else { model = ServiceFactory.BasicFunction.Get(id); }

            return View(model);
        }

        public string Grid(int rows, int page)
        {
            int count = 0;

            var list = ServiceFactory.BasicFunction.Grid(rows, page, out count);

            return JsonHelper.Grid(list, count);
        }

        public string AllGrid()
        {
            return JsonHelper.Serialize(ServiceFactory.BasicFunction.GetAll());
        }

        public string AllGridByMenu(string menuid)
        {
            return JsonHelper.Serialize(ServiceFactory.BasicFunction.GetByMenuId(menuid));
        }

        public string Save(BasicFunction model)
        {
            return ServiceFactory.BasicFunction.Save(model).Serialize();
        }

        public string Remove(string id)
        {
            return ServiceFactory.BasicFunction.Delete(id).Serialize();
        }

        public string SetOrder(string id, string order)
        {
            return ServiceFactory.BasicFunction.Order(id, order).Serialize();
        }
    }
}
